package com.lbd.system.service.impl;


import com.lbd.base.service.BaseServiceImpl;
import com.lbd.system.bean.EventLog;
import com.lbd.system.dao.EventLogRepository;
import com.lbd.system.service.EventLogService;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * Created by WangYajie on 2016/9/12.
 */
@Service
@Transactional
public class EventLogServiceImpl extends BaseServiceImpl<EventLog, EventLogRepository> implements EventLogService {
    private final Logger log = Logger.getLogger(this.getClass());

    @Override
    public Specification<EventLog> getSpecification(EventLog eventLog) {
        return null;
    }

    @Override
    public String buildJpql(EventLog eventLog, Map<String, Object> parameter) {
        StringBuilder jpqlBuilder = new StringBuilder("  from  EventLog t   ");
        if (eventLog != null) {
            if (StringUtils.isNotBlank(eventLog.getClassName())) {
                jpqlBuilder.append(" and  t.className like :className");
                parameter.put("className", "%" + eventLog.getClassName() + "%");
            }
        }
        jpqlBuilder.append(" order by createdDate desc");
        return jpqlBuilder.toString();
    }
}
